Display data inside a row
This example demonstrates how to use the List component to present structured data using custom row layouts. Each row displays a person's name and phone number in a clean and readable format, using stack-based layout components inspired by SwiftUI.
Overview
You will learn how to:
- Define a custom row component (
PersonRowView) - Use
Listto display a collection of items - Apply text styling and system icons
- Structure layouts using
VStackandHStack
Example Code
1. Import Dependencies and Define Data
2. Create a Row Component
The PersonRowView component renders the content of a single list row. It uses a vertical stack to separate the name and phone number, with appropriate font styles and colors.
3. Display the List in a Navigation Stack
Use NavigationStack and List to display all rows. The navigation title is set to describe the purpose of the view.
4. Present the View
Use Navigation.present to show the view, then exit the script after dismissal:
Summary
This pattern shows how to display data inside a row by:
- Structuring UI with layout components (
VStack,HStack) - Defining reusable, typed row components
- Presenting data collections cleanly using
List - Integrating icons and labels for better visual clarity
It is ideal for rendering lists of structured objects such as contacts, messages, or any custom data rows.
